/////////////////////////////////////////////////////////////////////
//	$file: $
//	$revision: $
//	$author: $
//	$datetime: $
//	first author: buggy

#ifndef	__SourceTree_h__
#define	__SourceTree_h__

#include	<QTreeWidget>
#include	<QTreeWidgetItem>
#include	<QFileInfo>


class	SourceTreeItem;


///////////////////////////////////////////////////////////
//	Source Navigator Tree Widget
class	SourceTree	:	public	QTreeWidget
{
private:
	struct	FuncKeyMap
	{
		Qt::KeyboardModifier	modifier;
		Qt::Key					key;
		Qt::Key					funcKey;
	};

public:
	SourceTree(const QString& rootPath, SourceNavigator* parentWidget);
	virtual	~SourceTree();

	void		Refresh();
	bool		IsValid()	const;
	QString		RootName()	const;
	QString		RootPath()	const;

	void		GoTop();
	void		GoBottom();

private:
	bool		open();

public:
	virtual	void		keyPressEvent(QKeyEvent* event);
protected:
	virtual	void		mouseDoubleClickEvent(QMouseEvent* event);

private:
	QString				_rootPath;
	SourceNavigator*	_parentWidget;


private:
	static	const	int			_KeyMapMax			= 32;
	static	const	FuncKeyMap	_KeyMap[_KeyMapMax];
};


///////////////////////////////////////////////////////////
//	Source Navigator Tree Widget Item
class	SourceTreeItem	:	public	QTreeWidgetItem
{
public:
	enum	TYPE
	{
		UNKNOWN	= 0,
		FILE,
		DIR,

		DIR_BIN,
		DIR_BUILD,
		C_SOURCE,
		CPP_SOURCE,
		HEADER,
		MAKEFILE,

		TYPE_MAX
	};

	enum	State
	{
		NORMAL		= 0x00,
		MODIFIED	= 0x01,
	};


public:
	static	SourceTreeItem*	Create(const QString& path, SourceTreeItem* parent);
	static	QIcon			Icon(TYPE type);

private:
	static	QVector<QIcon*>	_Icons;


protected:
	SourceTreeItem(const QFileInfo& fileinfo);

	bool	Initialize();

public:
	virtual	~SourceTreeItem();

	virtual	QVariant	data(int column, int role)	const;

public:
	TYPE		Type()			const	{	return _type;	}
	bool		CanOpen()		const;
	QString		Id()			const;
	QString		AbsolutePath()	const;
	QString		FileName()		const;
	QIcon		Icon()			const;

private:
	QFileInfo	_fileinfo;
	TYPE		_type;
	State		_state;
};


#endif	//	__SourceTree_h__
